# -*- coding: utf-8 -*-

import os
import Queue
from threading import Thread
from time import sleep
from xnotifier import cfg

notify_queue = Queue.Queue()


worker = None


class Notify(object):

    def __init__(self, mod="bell", title="", msg=""): 
        """ 
            type: mail, bell
            title: msg title
            msg: what's the tilte
        """
        self.mod = mod
        self.title = title
        self.msg = msg
        
    
    def do_notify(self):
        if self.mod == "mail":
            cmd = "email -s 'Hi, %s'  %s   -b -r %s "%(self.title, cfg.mailwho, cfg.smtp)
            os.system(cmd)

        if self.mod == "bell":
            os.system('/usr/bin/mplayer /usr/share/sounds/KDE-Im-Nudge.ogg')


def notify_thread():
    while True:
        notify = notify_queue.get()
        notify.do_notify()
        notify_queue.task_done()

def sound_notify():
    notify_queue.put(Notify()) 



def mail_notify(eagle=""):
    notify_queue.put(Notify("mail",eagle)) 


def init():
    #setup worker 
    worker = Thread(target = notify_thread)
    worker.start()
